﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DHQGHN.DAL.Common;
using DHQGHN.DAL.DAO.Admin;
using DHQGHN.DAL.Models.Admin;

namespace DHQGHN.DAL.BO.Admin
{
    public class CountryBO : BaseBO
    {
        #region Field list from database
        public const string FIELD_ID = "COUNTRY_ID";
        public const string FIELD_CODE_2 = "COUNTRY_CODE2";
        public const string FIELD_CODE_3 = "COUNTRY_CODE3";
        public const string FIELD_NUMERIC_CODE = "NUMERIC_CODE";
        public const string FIELD_COUNTRY_NAME = "COUNTRY_NAME";
        public const string FIELD_NATIONALITY_NAME = "NATIONALITY_NAME";
        public const string FIELD_DESCRIPTIONS = "DESCRIPTIONS";
        public const string FIELD_DELETED = "DELETED";
        #endregion

        public const string FIELD_RECORD_COUNT = "RecordCount";

        private String _connectionString;

        public CountryBO(string connString)
        {
            this._connectionString = connString;

        }
        public CountryBO()
        {
            this._connectionString = Common.ConnectionUtil.TKTHDS_METADATA_CONNECTION_STRING;

        }

        public CountryDAO _countryDAO;

        public CountryDAO CreateSQLDAO()
        {
            return new CountryDAO(_connectionString, DEFAULT_MAPPER_TYPE);
        }

        public DataPage<CountryModel> GetDynamicListPaging(CountryModel aModel, int pageSize, int pageIndex, bool compareEqual)
        {
            try
            {
                _countryDAO = CreateSQLDAO();
                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
                    {CountryModel.FIELD_ID,FIELD_ID},
                    {CountryModel.FIELD_CODE_2,FIELD_CODE_2},
                    {CountryModel.FIELD_CODE_3,FIELD_CODE_3},  
                    {CountryModel.FIELD_NUMERIC_CODE,FIELD_NUMERIC_CODE},  
                    {CountryModel.FIELD_COUNTRY_NAME,FIELD_COUNTRY_NAME},  
                    {CountryModel.FIELD_NATIONALITY_NAME,FIELD_NATIONALITY_NAME},  
                    {CountryModel.FIELD_DESCRIPTIONS,FIELD_DESCRIPTIONS},
                    {CountryModel.FIELD_DELETED,FIELD_DELETED},
                    {CountryModel.FIELD_RECORD_COUNT, FIELD_RECORD_COUNT}
                };
                return _countryDAO.GetDynamicListPaging(aModel, pageSize, pageIndex, mapDictionary, compareEqual);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public CountryModel GetCountryById(string id)
        {
            try
            {
                _countryDAO = CreateSQLDAO();

                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
                    {CountryModel.FIELD_ID,FIELD_ID},
                    {CountryModel.FIELD_CODE_2,FIELD_CODE_2},
                    {CountryModel.FIELD_CODE_3,FIELD_CODE_3},  
                    {CountryModel.FIELD_NUMERIC_CODE,FIELD_NUMERIC_CODE},  
                    {CountryModel.FIELD_COUNTRY_NAME,FIELD_COUNTRY_NAME},  
                    {CountryModel.FIELD_NATIONALITY_NAME,FIELD_NATIONALITY_NAME},  
                    {CountryModel.FIELD_DESCRIPTIONS,FIELD_DESCRIPTIONS},
                    {CountryModel.FIELD_DELETED,FIELD_DELETED},
                    {CountryModel.FIELD_RECORD_COUNT, FIELD_RECORD_COUNT}
                };

                return _countryDAO.GetById(id, mapDictionary);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public bool createOrUpdateCountry(CountryModel model)
        {
            try
            {
                _countryDAO = CreateSQLDAO();
                return _countryDAO.createOrUpdateCountry(model);
            }
            catch (Exception e)
            {
                return false;
            }
        }

        public bool deleteCountry(string[] listID)
        {
            try
            {
                _countryDAO = CreateSQLDAO();
                return _countryDAO.deleteCountry(listID);
            }
            catch (Exception e)
            {
                return false;
            }
        }

        public bool activeCountry(string id, int request)
        {
            try
            {
                _countryDAO = CreateSQLDAO();
                return _countryDAO.activeCountry(id, request);
            }
            catch (Exception e)
            {
                return false;
            }
        }
    }
}